package process_demo.review.about_timer.impl;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * @author haomin
 * @date 2022/09/21 19:23
 **/
abstract class MyTimerTask1 implements Comparable<MyTimerTask> {
    long runAt;     // 这个任务应该在何时运行（记录为 ms 为单位的时间戳）
    abstract public void run();

    @Override
    public int compareTo(MyTimerTask o) {
        if (runAt < o.runAt) {
            return -1;
        } else if (runAt > o.runAt) {
            return 1;
        } else {
            return 0;
        }
    }
}

public class dd {
    private final PriorityBlockingQueue<MyTimerTask1> queue = new PriorityBlockingQueue();

    class Worker extends Thread{
        @Override
        public void run() {
            while (true){
                MyTimerTask1 task1 = null;
                try {
                    task1 = queue.take();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                long now = System.currentTimeMillis();
                long delay = task1.runAt-now;
                if(delay <= 0){
                    task1.run();
                }else {

                }
            }
        }
    }

}